-
Notifications
You must be signed in to change notification settings - Fork 279
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support Drag and Drop of Folders as well as files, fixes #668 #659
Conversation
Your build failed around the eslint:src section.. my PR also failed around that sort of thing. How do we fix that?? |
@Blackweda you just have to fix the lint errors. My code has some, it seems. I'll fix and push a patch. You can test it locally first to make sure lint passes. |
I also added another commit that fixes https://github.com/mozilla/thimble.mozilla.org/issues/1886, allowing you to drag files/folders onto an existing dir vs. always importing to the project root. My code also auto-opens subdirs as you hover over them, in case they are closed. |
@Pomax this PR is mostly dedicated to you. I should get you to test it and see if it works well for your use cases. Some things to try/note:
I don't have access to Windows and IE/Edge, so I don't know what it does in these browsers. But on Mac, it's working in Safari, Chrome, Firefox, and Opera. I'm fairly confident that I can do 2 more patches to follow this that will support:
I've now gotten the hang of the filetree code :) |
I tried this with a folder on my desktop called "test" containing |
Edge 14 does not like folder drag-and-drop, it would appear. I can't drop a folder onto the filetree in it. |
do we filter on extension @humphd? if I rename my |
That Folder drag and drop is not going to work in IE/Edge (yet), no, so that's known. Dragging a bunch of files should work, though, in all browsers. |
barring that weird extension filtering, this actually seems to work pretty well. I tried dragging the folder into itself a few times. Works pretty well too - does highlight a question though: do we want a file-overwrite warning when a drop operation will overwrite existing files? |
if the overwrite issue is known and we have issues outstanding, then this is R+ from me. |
Thanks for the reviews. I'm going to wait on a few other PRs to land that touch this code, and then I'll circle back, rebase, and try to get this in. |
… dropping deep into the filetree.
@gideonthomas I've rebased this, and fixed a few things I noticed in testing. Do you want to take a look before I land? |
sure |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mainly just nits in the code!
I tested this out and it works well! One thing I noticed was that in Thimble, while dnd'ing folders/files/archives works perfectly if you do it directly even if there is a file in the folder that exceeds that max file size limit. However, if we use the "Upload Files" dialog and drag a folder (or archive or just the file) containing a file that is more than the max file size, it shows the error and then the editor just hangs. I feel like that is a known issue, but I'm not sure. If not, let's file a follow-up to fix in Thimble since we need to fix the strings in the "Upload Files" dialog as well (since we can upload folders now too)
}); | ||
}; | ||
|
||
exports.create = function(byteLimit) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rename to options
since it's not just byteLimit
?
} | ||
}; | ||
|
||
exports.create = function(byteLimit) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here...options
vs. byteLimit
?
@@ -538,7 +551,8 @@ define(function (require, exports, module) { | |||
className: this.getClasses("jstree-leaf"), | |||
onClick: this.handleClick, | |||
onMouseDown: this.handleMouseDown, | |||
onDoubleClick: this.handleDoubleClick | |||
onDoubleClick: this.handleDoubleClick, | |||
onDragEnter: this.handleDragEnter |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's interesting that we don't need to bind to this
here even though we use this
inside handleDragEnter
. Maybe it does .call(this, ...)
?
src/utils/DragAndDrop.js
Outdated
var files = event.dataTransfer.files; | ||
var types = event.dataTransfer.types; | ||
|
||
if ((!files || !files.length) && types) { // We only want to check if a string of text was dragged into the editor |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if( !(files && files.length) && types )
I saw this tweet yesterday about CodePen's ability to let you drag and drop folders as well as files:
https://twitter.com/CodePen/status/843908650997600256?s=03
When I wrote our drag and drop stuff, browsers only supported files. So I did some research, and sure enough, Edge, Chrome, and Firefox all support it (hilariously, all via a
webkit*
prefix method). The drag and drop and file api specs are a bit of a dog's breakfast, however, I was able to make it all work.With this patch, I've reworked our code to support both the new
webkit
way (which supports folders and files) and also the old way, which only works with folders. Both ways still support auto-expanding of.zip
and.tar
files contained within.I could use some help really testing this on various browsers and files/folders. cc @Pomax and @flukeout.